<template>
	<section style="width:100%">
		<section>
			<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
				<el-form :inline="true">
					<el-form-item>
						<el-input v-model="userId" placeholder="接收人ID"></el-input>
					</el-form-item>
					<el-form-item>
						<el-input v-model="giveId" placeholder="赠送人ID"></el-input>
					</el-form-item>
					<!--<el-form-item label="类型">-->
						<!--<el-select v-model="value" placeholder="请选择">-->
							<!--<el-option-->
									<!--v-for="item in options"-->
									<!--:key="item.value"-->
									<!--:label="item.label"-->
									<!--:value="item.value">-->
							<!--</el-option>-->
						<!--</el-select>-->
					<!--</el-form-item>-->
					<!--<el-form-item label="赠送类型">-->
						<!--<el-select v-model="value" placeholder="请选择">-->
							<!--<el-option-->
									<!--v-for="item in options"-->
									<!--:key="item.value"-->
									<!--:label="item.label"-->
									<!--:value="item.value">-->
							<!--</el-option>-->
						<!--</el-select>-->
					<!--</el-form-item>-->
					<el-form-item label="赠送开始时间">
						<el-date-picker
								v-model="cashStart"
								type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss"
								placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
					<el-form-item label="赠送结束时间">
						<el-date-picker
								v-model="cashEnd"
								type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss"
								placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
					<!--<el-form-item label="状态">-->
						<!--<el-select v-model="stateValue" placeholder="请选择">-->
							<!--<el-option-->
									<!--v-for="item in options"-->
									<!--:key="item.id"-->
									<!--:label="item.label"-->
									<!--:value="item.id">-->
							<!--</el-option>-->
						<!--</el-select>-->
					<!--</el-form-item>-->
					<el-form-item>
						<el-button type="primary" v-on:click="getUsers(pageSize)">查询</el-button>
					</el-form-item>
					<!--<el-form-item>-->
						<!--<el-button type="primary" >重置</el-button>-->
					<!--</el-form-item>-->
				</el-form>
				<!--<el-form :inline="true">-->
					<!--<el-form-item label="今日玩家上分">-->
						<!--<label>213212999999</label>-->
					<!--</el-form-item>-->
					<!--<el-form-item label="今日玩家下分">-->
						<!--<label>213212999999</label>-->
					<!--</el-form-item>-->
				<!--</el-form>-->
			</el-col>
			<!--列表-->
			<el-table :data="users" stripe highlight-current-row v-loading="listLoading" style="width: 100%;" :default-sort = "{prop: 'time', order: 'descending'}">
				<el-table-column prop="id" label="#" width="100">
				</el-table-column>
				<el-table-column prop="userid" label="接收玩家ID" sortable>
				</el-table-column>
				<el-table-column prop="nickname" label="接收玩家昵称">
				</el-table-column>
				<el-table-column prop="receiveType" label="接收玩家类型" >
				</el-table-column>
				<el-table-column prop="destination" label="赠送玩家ID" sortable>
				</el-table-column>
				<el-table-column prop="dnickname" label="赠送玩家昵称">
				</el-table-column>
				<el-table-column prop="giveType" label="赠送玩家类型" >
				</el-table-column>
				<el-table-column prop="time" label="赠送时间" sortable>
				</el-table-column>
				<el-table-column prop="amount" label="赠送金币数" sortable>
				</el-table-column>
				<!--<el-table-column prop="name" label="赠送金币">-->
				<!--</el-table-column>-->
				<!--<el-table-column prop="name" label="赠送后金币">-->
				<!--</el-table-column>-->
				<!--<el-table-column prop="name" label="玩家B昵称">-->
				<!--</el-table-column>-->
				<!--<el-table-column prop="name" label="玩家B账号类型">-->
				<!--</el-table-column>-->
				<!--<el-table-column prop="name" label="接收前金币">-->
				<!--</el-table-column>-->
				<!--<el-table-column prop="name" label="接收后金币">-->
				<!--</el-table-column>-->
				<!--<el-table-column prop="name" label="状态">-->
				<!--</el-table-column>-->
			</el-table>

			<!--工具条-->
			<el-col :span="24" class="toolbar">
				<el-pagination layout="sizes, total, prev, pager, next" :page-sizes="[15, 30, 50]" @current-change="handleCurrentChange" @size-change="handleSizeChange"  :page-size="pageSize" :total="total" style="float:right;">
				</el-pagination>
			</el-col>
		</section>
	</section>
</template>

<script>
    import base64 from '../../api/base64'
    export default {
        data() {
            return {
                stateValue:'1',
                userId:'',
				giveId:'',
                cashStart:'',
				cashEnd:'',
                listLoading:false,
                users:[],
                total:0,
                page:1,
				pageSize:15
            }
        },
        created(){
            let agentId = sessionStorage.getItem('searchAgentId')
            if (agentId){
                this.userId = agentId
                sessionStorage.removeItem('searchAgentId')
            }
        },
        methods: {
            handleSizeChange(val) {
                this.pageSize = val
                this.getUsers(this.pageSize);
            },
            handleCurrentChange(val) {
                this.page = val;
                this.getUsers(this.pageSize);
            },
            //获取用户列表
            getUsers(page) {
                this.listLoading = true;
                let loginStart,loginEnd
                if (this.cashStart || this.cashEnd){
                    loginStart = Date.parse(new Date(this.cashStart))
                    loginEnd = Date.parse(new Date(this.cashEnd))
                }else{
                    loginStart = ''
                    loginEnd =''
                }
                this.$axios.get('/give-records?userid='+this.userId+'&index='+this.page+'&size='+page+'&destination='+this.giveId+'&tradeatstart='+loginStart+'&tradeatend='+loginEnd+'&type='+this.stateValue,{},this.global().token).then((res)=>{
                    if (res.status == 200){
                        this.total = res.data.count
                        let userTable = res.data.data
                        let base = new base64.Base64()
                        userTable.forEach((val)=>{
                            if (val.nickname){
                                val.nickname =  base.decode(val.nickname)
                            }
                            if (val.dnickname){
                                val.dnickname =  base.decode(val.dnickname)
                            }
                            val.time = this.changeDate(val.tradeat)
                            val.amount = parseFloat(val.amount)/1000
                            // val.receiveType = val.usertype.toString().replace('','玩家').replace('1','代理')
                            // val.giveType = val.dusertype.toString().replace('','玩家').replace('1','代理')
                        })
                        this.users = userTable
                        this.listLoading = false
                    }else{
                        this.$message({message: res.data, type: 'error'});
                        this.listLoading = false
                    }
                })
            },
            editCash(id,state){
                this.$axios.patch('/user-withdrawl/'+id,{state:parseInt(state)},this.global().token).then((res)=>{
                    if (res.status == 200){
                        this.$message({message: '操作成功', type: 'success'});
                        this.getUsers(this.pageSize)
                    }else{
                        this.$message({message: res.data, type: 'error'});
                    }
                })
            }
        },
        mounted() {
            this.cashStart = this.Todate1(new Date(new Date()-24*60*60*7000),'yyyy-MM-dd HH:mm:ss')
            this.cashEnd =  this.Todate(new Date(new Date()),'yyyy-MM-dd HH:mm:ss')
            this.getUsers(this.pageSize);
        }
    }

</script>

<style scoped lang="stylus">
	.agent-path
		display flex
		padding-bottom 10px
		&>p
			padding-right 10px
		&>h3
			cursor pointer
</style>